package com.bilin.coin.list;

import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bilin.coin.R;
import com.bilin.coin.bean.CoinRecordBean;
import com.bilin.coin.common.base.BaseAppCompatActivity;
import com.bilin.coin.network.RequestUtils;
import com.bilin.coin.utils.DensityUtils;
import com.bilin.coin.utils.SpacesItemDecoration;
import com.bilin.coin.widget.AbsPullToRefreshRecycleView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class RechargeWithdrawRecordList extends AbsPullToRefreshRecycleView<CoinRecordBean.RecordsBean> {

    int type;//0充1提

    String id;
    String coinName;

    public RechargeWithdrawRecordList(BaseAppCompatActivity activity, int type) {
        super(activity, true, false);
        this.type = type;
    }

    public RechargeWithdrawRecordList(BaseAppCompatActivity activity, int type, String id, String coinName) {
        super(activity, true, false);
        this.type = type;
        this.id = id;
        this.coinName = coinName;
    }

    public BaseQuickAdapter obtainAdapter(){
        return adapter;
    }

    @Override
    public int fillPageSize() {
        return 10;
    }

    @Override
    public boolean isPost() {
        return false;
    }

    @Override
    public List parseListDataAndFillTotal(String dataJson) {
        CoinRecordBean productHomeBean = RequestUtils.getGson().fromJson(dataJson, CoinRecordBean.class);
        totalCount = productHomeBean.getTotal();
        return productHomeBean.getRecords();
    }

    @Override
    public Map<String, String> fillParams() {
        HashMap params = new HashMap();
        params.put("currentPage",page+"");
        params.put("pageSize",pageSize+"");
        params.put("id",id+"");
        return params;
    }

    @Override
    protected RecyclerView.LayoutManager fillLayoutManger() {
        LinearLayoutManager manager = new LinearLayoutManager(activity);
        manager.setOrientation(RecyclerView.VERTICAL);
        recyclerView.addItemDecoration(new SpacesItemDecoration(1, DensityUtils.dp2px(activity, 10), 0x1888));
        return manager;
    }

    @Override
    public String fillUrl() {
        return type==0?"/api/coin-log/deposit/history":"/api/coin-log/withdraw/log";
    }

    @Override
    protected void convertItem(BaseViewHolder helper, CoinRecordBean.RecordsBean item) {
        helper.setText(R.id.tv_num,item.getAmount()+coinName);
        helper.setText(R.id.tv_time,item.getCreateTime());
        TextView tv_sn = helper.getView(R.id.tv_sn);
        RelativeLayout rl_trade_num = helper.getView(R.id.rl_trade_num);
        tv_sn.setText(item.getHash());
        tv_sn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.copeClipSuccess(tv_sn);
            }
        });
        //（充值：0 同步中 1 充值成功） | （提现： 0等待提现 1正在处理 2提现成功 3用户撤销 4系统撤销）
        if (type == 0) {//0充1提
            rl_trade_num.setVisibility(View.VISIBLE);
            switch (item.getStatus()) {
                case 0:
                    helper.setText(R.id.tv_status, R.string.syn_ing);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.coin_color_red));
                    break;
                case 1:
                    helper.setText(R.id.tv_status, R.string.recharge_success);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.colorPrimary));
                    break;
            }

        } else {
            View view = helper.getView(R.id.v_status);
            TextView tv_cancel = helper.getView(R.id.tv_cancel);
            rl_trade_num.setVisibility(View.GONE);
            switch (item.getStatus()) {
                case 0:
                    view.setVisibility(View.VISIBLE);
                    tv_cancel.setVisibility(View.VISIBLE);
                    helper.setText(R.id.tv_status, R.string.wait_withdraw);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.coin_color_red));
                   /* tv_cancel.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            cancel(item);
                        }
                    });*/
                    helper.addOnClickListener(R.id.tv_cancel);
                    break;
                case 1:
                    view.setVisibility(View.GONE);
                    tv_cancel.setVisibility(View.GONE);
                    helper.setText(R.id.tv_status, R.string.dispose_ing);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.coin_color_red));
                    break;
                case 2:
                    view.setVisibility(View.GONE);
                    tv_cancel.setVisibility(View.GONE);
                    helper.setText(R.id.tv_status, R.string.withdraw_success);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.colorPrimary));
                    break;
                case 3:
                    view.setVisibility(View.GONE);
                    tv_cancel.setVisibility(View.GONE);
                    helper.setText(R.id.tv_status, R.string.cancel_user);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.coin_color_red));
                    break;
                case 4:
                    view.setVisibility(View.GONE);
                    tv_cancel.setVisibility(View.GONE);
                    helper.setText(R.id.tv_status, R.string.cancel_sys);
                    helper.setTextColor(R.id.tv_status, activity.getResources().getColor(R.color.coin_color_red));
                    break;
            }
        }
    }



    @Override
    protected int fillItemLayout() {
        return R.layout.item_coin_record;
    }
}
